; ModuleID = 'tests/m3/callingSimpleFunction.bal'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-linux-gnu"

%letter = type i8
%number = type i32
%sentence = type i8*

@.fmt_d = private constant [3 x i8] c"%d\00", align 1 ; <[3 x i8]*> [#uses=1]
@.io.error = private constant [53 x i8] c"IOError: Could not read integer from standard input!\00", align 1 ; <[53 x i8]*> [#uses=0]
@.fmt_s = private constant [3 x i8] c"%s\00", align 1 ; <[3 x i8]*> [#uses=1]
@.fmt_c = private constant [5 x i8] c"'%c'\00", align 1 ; <[5 x i8]*> [#uses=0]
@0 = private constant [20 x i8] c"Tell me a number\0A> \00", align 1 ; <[20 x i8]*> [#uses=1]
@1 = private constant [7 x i8] c"arr's \00", align 1 ; <[7 x i8]*> [#uses=1]
@2 = private constant [11 x i8] c" piece is \00", align 1 ; <[11 x i8]*> [#uses=1]
@3 = private constant [2 x i8] c"\0A\00", align 1 ; <[2 x i8]*> [#uses=1]

declare i32 @printf(i8*, ...)

declare i32 @scanf(i8*, ...)

declare void @abort()

define i32 @simpleSum(i32 %l, i32 %m) {
entry:
  %l.param = alloca i32                           ; <i32*> [#uses=2]
  store i32 %l, i32* %l.param
  %m.param = alloca i32                           ; <i32*> [#uses=2]
  store i32 %m, i32* %m.param
  br label %body

body:                                             ; preds = %entry
  %tmp = getelementptr i32* %l.param, i32 0       ; <i32*> [#uses=1]
  %l1 = load i32* %tmp                            ; <i32> [#uses=1]
  %tmp3 = getelementptr i32* %m.param, i32 0      ; <i32*> [#uses=1]
  %m2 = load i32* %tmp3                           ; <i32> [#uses=1]
  %"+" = add i32 %l1, %m2                         ; <i32> [#uses=1]
  ret i32 %"+"
}

define i32 @main(i32 %argc, i8** %argv) {
entry:
  %argc.param = alloca i32                        ; <i32*> [#uses=1]
  store i32 %argc, i32* %argc.param
  %argv.param = alloca i8**                       ; <i8***> [#uses=1]
  store i8** %argv, i8*** %argv.param
  %x = alloca i32                                 ; <i32*> [#uses=3]
  %tmp = getelementptr i32* %x, i32 0             ; <i32*> [#uses=1]
  store i32 0, i32* %tmp
  %y = alloca i32                                 ; <i32*> [#uses=3]
  %tmp22 = getelementptr i32* %y, i32 0           ; <i32*> [#uses=1]
  store i32 0, i32* %tmp22
  %times = alloca i32                             ; <i32*> [#uses=14]
  %tmp23 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  store i32 0, i32* %tmp23
  %tmp24 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times1 = load i32* %tmp24                      ; <i32> [#uses=1]
  %arr = alloca i32, i32 %times1                  ; <i32*> [#uses=3]
  %tmp25 = getelementptr i32* %arr, i32 0         ; <i32*> [#uses=1]
  store i32 0, i32* %tmp25
  br label %body

body:                                             ; preds = %entry
  %tmp26 = getelementptr i32* %x, i32 0           ; <i32*> [#uses=1]
  store i32 3, i32* %tmp26
  %printf = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_s, i64 0, i64 0), [20 x i8]* @0) ; <i32> [#uses=0]
  %tmp27 = getelementptr i32* %y, i32 0           ; <i32*> [#uses=1]
  %tmp28 = call i32 (i8*, ...)* @scanf(i8* noalias getelementptr inbounds ([3 x i8]* @.fmt_d, i64 0, i64 0), i32* %tmp27) nounwind ; <i32> [#uses=0]
  %tmp29 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  store i32 1000, i32* %tmp29
  br label %eventually.check

eventually.check:                                 ; preds = %eventually.true, %body
  %tmp30 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times2 = load i32* %tmp30                      ; <i32> [#uses=1]
  %tmp31 = icmp eq i32 %times2, 0                 ; <i1> [#uses=1]
  %"~" = xor i1 %tmp31, true                      ; <i1> [#uses=1]
  br i1 %"~", label %eventually.true, label %eventually.merge

eventually.true:                                  ; preds = %eventually.check
  %tmp32 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times3 = load i32* %tmp32                      ; <i32> [#uses=1]
  %tmp33 = getelementptr i32* %arr, i32 %times3   ; <i32*> [#uses=1]
  %tmp34 = getelementptr i32* %x, i32 0           ; <i32*> [#uses=1]
  %x4 = load i32* %tmp34                          ; <i32> [#uses=1]
  %tmp35 = getelementptr i32* %y, i32 0           ; <i32*> [#uses=1]
  %y5 = load i32* %tmp35                          ; <i32> [#uses=1]
  %tmp36 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times6 = load i32* %tmp36                      ; <i32> [#uses=1]
  %tmp37 = mul i32 %y5, %times6                   ; <i32> [#uses=1]
  %"<call>" = call i32 @simpleSum(i32 %x4, i32 %tmp37) ; <i32> [#uses=1]
  store i32 %"<call>", i32* %tmp33
  %tmp38 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %tmp39 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times7 = load i32* %tmp39                      ; <i32> [#uses=1]
  %tmp40 = sub i32 %times7, 1                     ; <i32> [#uses=1]
  store i32 %tmp40, i32* %tmp38
  br label %eventually.check

eventually.merge:                                 ; preds = %eventually.check
  %tmp41 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  store i32 100, i32* %tmp41
  br label %eventually.check10

eventually.check10:                               ; preds = %eventually.true9, %eventually.merge
  %tmp42 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times11 = load i32* %tmp42                     ; <i32> [#uses=1]
  %tmp43 = icmp eq i32 %times11, 0                ; <i1> [#uses=1]
  %"~12" = xor i1 %tmp43, true                    ; <i1> [#uses=1]
  br i1 %"~12", label %eventually.true9, label %eventually.merge8

eventually.true9:                                 ; preds = %eventually.check10
  %printf13 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_s, i64 0, i64 0), [7 x i8]* @1) ; <i32> [#uses=0]
  %tmp44 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times14 = load i32* %tmp44                     ; <i32> [#uses=1]
  %printf15 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_d, i64 0, i64 0), i32 %times14) ; <i32> [#uses=0]
  %printf16 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_s, i64 0, i64 0), [11 x i8]* @2) ; <i32> [#uses=0]
  %tmp45 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times17 = load i32* %tmp45                     ; <i32> [#uses=1]
  %tmp46 = getelementptr i32* %arr, i32 %times17  ; <i32*> [#uses=1]
  %arr18 = load i32* %tmp46                       ; <i32> [#uses=1]
  %printf19 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_d, i64 0, i64 0), i32 %arr18) ; <i32> [#uses=0]
  %printf20 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.fmt_s, i64 0, i64 0), [2 x i8]* @3) ; <i32> [#uses=0]
  %tmp47 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %tmp48 = getelementptr i32* %times, i32 0       ; <i32*> [#uses=1]
  %times21 = load i32* %tmp48                     ; <i32> [#uses=1]
  %tmp49 = sub i32 %times21, 1                    ; <i32> [#uses=1]
  store i32 %tmp49, i32* %tmp47
  br label %eventually.check10

eventually.merge8:                                ; preds = %eventually.check10
  ret i32 0
}
